using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using dpa.Library.Services;
using dpa.Library.ViewModels;
using dpa.Views;
using Microsoft.Extensions.DependencyInjection;

namespace dpa;

public partial class App : Application
{
    /*public static IServiceProvider Services;

    public ResultViewModel ResultViewModel => Services.GetRequiredService<ResultViewModel>();*/

    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    /*public static new App? Current = (App?)Application.Current;

    private static IServiceProvider ConfigureServices()
    {
        var serviceCollection = new ServiceCollection();

        serviceCollection.AddSingleton<ResultViewModel>();

        serviceCollection.AddSingleton<IPoetryStorage, PoetryStorage>();
        serviceCollection.AddSingleton<IPreferenceStorage, FilePreferenceStorage>();

        return serviceCollection.BuildServiceProvider();
    }

    public App() => Services = ConfigureServices();*/

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            // Line below is needed to remove Avalonia data validation.
            // Without this line you will get duplicate validations from both Avalonia and CT
            BindingPlugins.DataValidators.RemoveAt(0);
            desktop.MainWindow = new MainWindow();
            //ServiceLocator.Current.RootNavigationService.NavigateTo(nameof(TodayViewModel));
        }

        base.OnFrameworkInitializationCompleted();
    }
}